<template>
  <div>
    <el-form :inline="true">
      <el-form-item label="" v-if="isAuth('hotel:hotelseller:list')">
        <el-select
          multiple
          collapse-tags
          clearable
          style="width:180px;"
          v-model="sellerIds"
          filterable
          remote
          reserve-keyword
          @change="selectSeller"
          placeholder="商家名称"
          :remote-method="remoteMethod"
          :loading="loading"
        >
          <el-option v-for="item in platformSeller" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="shaixuan = !shaixuan">高级搜索</el-button>
      </el-form-item>
    </el-form>

    <el-collapse-transition>
      <div v-show="shaixuan">
        <el-form :model="dataForm" @keyup.enter.native="getDataList()" label-width="120px">
          <el-form-item label="入住日期">
            <el-date-picker
              v-model="dataForm.ruzhu1"
              type="datetime" size="small"
              placeholder="选择日期时间"
              align="right"
              :picker-options="pickerOptions"
            ></el-date-picker>
            <el-date-picker
              v-model="dataForm.ruzhu2"
              type="datetime" size="small"
              placeholder="选择日期时间"
              align="right"
              :picker-options="pickerOptions"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="离店日期" style="width: 100%;">
            <el-date-picker size="small"
              v-model="dataForm.lidian1"
              type="datetime"
              placeholder="选择日期时间"
              align="right"
              :picker-options="pickerOptions"
            ></el-date-picker>
            <el-date-picker size="small"
              v-model="dataForm.lidian2"
              type="datetime"
              placeholder="选择日期时间"
              align="right"
              :picker-options="pickerOptions"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="入住类型" style="width:100%;">
            <!-- 入住类型（0全天1时租2自用3免费） -->
            <el-select v-model="dataForm.checkinType" size="small" placeholder="请选择入住类型">
                <el-option label="全部" value=""></el-option>
                <el-option label="全天房" :value="0"></el-option>
                <el-option label="钟点房" :value="1"></el-option>
                <el-option label="自用房" :value="2"></el-option>
                <el-option label="免费房" :value="3"></el-option>
              </el-select>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-delete" @click="clearShaiXuan">清空筛选</el-button>
            <el-button type="primary" icon="el-icon-search" @click="getDataList()">{{ $t('Common.Query') }}</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-collapse-transition>

    <el-table
      style="width: 100%"
      row-key="id"
      ref="unitedHouseList"
      default-expand-all
      :data="unitedHouseList"
      tooltip-effect="dark"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
<!--      <el-table-column label="商家">
        <template slot-scope="scope">
         {{ scope.row.sellername}}
        </template>
      </el-table-column> -->
      <el-table-column label="房号">
        <template slot-scope="scope">
           {{ scope.row.roomNum}}
        </template>
      </el-table-column>
      <el-table-column label="抵店时间">
        <template slot-scope="scope">
           {{ scope.row.arrivalsTime}}
        </template>
      </el-table-column>
      <el-table-column label="预离时间">
        <template slot-scope="scope">
           {{ scope.row.predissociationTime}}
        </template>
      </el-table-column>
      <el-table-column label="天数">
        <template slot-scope="scope">
           {{ scope.row.tianshu}}
        </template>
      </el-table-column>
      <el-table-column label="房型">
        <template slot-scope="scope">
           {{ scope.row.roomnames}}
        </template>
      </el-table-column>
      <el-table-column label="入住类型">
        <template slot-scope="scope">
          <span v-if="scope.row.classify == 0">全天房</span>
          <span v-if="scope.row.classify == 1">钟点房</span>
          <span v-if="scope.row.classify == 2">自用房</span>
          <span v-if="scope.row.classify == 3">免费房</span>
        </template>
      </el-table-column>
      <el-table-column label="房价">
        <template slot-scope="scope">
 <!--            <el-button @click="addfj(scope.row.sign)">房价</el-button> -->
             <el-popover placement="right" width="200" trigger="hover">
               <el-form label-width="100px" :inline="true" style="max-height: 300px !important;overflow-y: auto;">
                 <div v-for="(item, index) in scope.row.prices.dateList" :key="index">
                   <el-form-item v-for="(value, key) in item" :key="key" :label="key + '：'">
                     <span>{{ value }} 元</span>
                   </el-form-item>
                 </div>
               </el-form>
              <span slot="reference" v-if="scope.row.prices.dateList!=undefined">{{ scope.row.prices.dateList[0][currDate] }}</span>
             </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="总房费">
        <template slot-scope="scope">
           {{ scope.row.roomPrice}}
        </template>
      </el-table-column>
      <el-table-column label="已消费">
        <template slot-scope="scope">
           {{ scope.row.consumption}}
        </template>
      </el-table-column>
      <el-table-column label="来源">
        <template slot-scope="scope">
          <span v-if="scope.row.sourceType == 0">散客</span>
          <span v-if="scope.row.sourceType == 1">会员</span>
          <span v-if="scope.row.sourceType == 2">协议单位</span>
          <span v-if="scope.row.sourceType == 3">中介</span>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination
      style="margin-top: 15px;text-align: right;"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <changeRoom v-if="changeRoomVisible" ref="changeRoom" @refreClosing="getDataList"></changeRoom>
    <joinRoom v-if="joinRoomVisible" ref="joinRoom" @refreClosing="getDataList"></joinRoom>
    <xuzhuTiqian v-if="xuzhuTiqianVisible" ref="xuzhuTiqian" @refreClosing="getDataList" @refreshDataList="getDataList()"></xuzhuTiqian>
    <closingRoom v-if="closingRoomVisible" ref="closingRoom" @refreClosing="getDataList" @refreshDataList="getDataList()"></closingRoom>
    <ruzhang v-if="ruzhangVisible" ref="ruzhang" @refreshDataList="getDataList()"></ruzhang>
    <addPeople v-if="addPeopleVisible" ref="addPeople" @refreClosing="getDataList" @refreshDataList="getDataList()"></addPeople>


     <el-dialog    title="房价"
      :visible.sync="showfj"
       v-if="showfj">
       <el-table
         :data="fj"
         border
         v-loading="dataListLoading"
         style="width: 100%;">
         <el-table-column
           type="selection"
           header-align="center"
           align="center"
           width="50">
         </el-table-column>
         <el-table-column
           prop="name"
           header-align="center"
           align="center"
           label="姓名">
         </el-table-column>
       <el-table-column
         prop="sex"
         header-align="center"
         align="center"
         label="性别">
         <template slot-scope="scope">
          <label v-if="scope.row.sex==1">男</label>
           <label v-if="scope.row.sex==2">女</label>
         </template>
       </el-table-column>
       </el-table>

     </el-dialog>

  </div>
</template>

<script>
import changeRoom from '../floorRoomSign/changeRoom';
import joinRoom from '../floorRoomSign/joinRoom';
import closingRoom from '../floorRoomSign/closingRoom';
import xuzhuTiqian from '../floorRoomSign/xuzhuTiqian';
import ruzhang from '../floorRoomSign/ruzhang';
import addPeople from '../floorRoomSign/addPeople';
import moment from 'moment';
export default {
  props:{
    tguesid:{
      type:String
    }
  },
  data() {
    return {
      pickerOptions: {

      },
      loading: false,
      shaixuan: false,
      addPeopleVisible: false,
      ruzhangVisible: false,
      closingRoomVisible: false,
      changeRoomVisible: false,
      joinRoomVisible: false,
      xuzhuTiqianVisible: false,
      currDate: moment().format('YYYY-MM-DD'),
      unitedHouseList: [],
      platformSeller: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      sj:{
        one:0,
        two:0,
        three:0,
        four:0,
        five:0,
      },
      dataForm: {
        state: '1',
        externalNo: '',
        sysNo: '',
        checkinType: '',
        sourceType: '',
        ruzhu1:'',
        ruzhu2:'',
        lidian1:'',
        lidian2:'',
        creat1:'',
        creat2:'',
      },
      showfj:false,
      fj:[],
      sellerIds:[],
    };
  },
  components: { changeRoom, joinRoom, closingRoom, xuzhuTiqian, ruzhang, addPeople },
  activated() {

    this.remoteMethod();
  },

created() {
    this.getDataList();
},
  methods: {
    addfj(json){

      var json=json[dateList];
      for(var i=0;i<json.length;i++){
          console.log(i+"----"+json[i][0]);
           console.log(i+"----"+json[i][1]);
      }
      this.showfj=true;
    },
    //清空筛选
    clearShaiXuan(){
      Object.assign(this.dataForm, this.$options.data().dataForm)
      this.getDataList();
    },
    addPeopleBtn(item) {
      this.addPeopleVisible = true;
      this.$nextTick(() => {
        this.$refs.addPeople.init({
          sellerId: item.sellerId,
          floorRoomId: item.floorRoomId,
          arrivalsTime: item.arrivalsTime,
          predissociationTime: item.predissociationTime,
          roomPrice: item.roomPrice,
          singleId: item.singleId,
          sign: item.sign
        });
      });
    },
    // 入账
    ruzhangHandle(item) {
      this.ruzhangVisible = true;
      this.$nextTick(() => {
        this.$refs.ruzhang.init({
          id: item.id,
          singleId: item.singleId
        });
      });
    },
    xuzhuTiqian(item) {
      console.log(item);
      this.xuzhuTiqianVisible = true;
      this.$nextTick(() => {
        this.$refs.xuzhuTiqian.init({
          id: item.id,
          predissociationTime: item.predissociationTime,
          arrivalsTime: item.arrivalsTime,
          singleId: item.singleId,
          floorRoomId: item.floorRoomId,
          roomId: item.hotelFloorRoomEntity.roomId
        });
      });
    },
    jieZhangTuiFang(item) {
      this.closingRoomVisible = true;
      this.$nextTick(() => {
        this.$refs.closingRoom.init({ singleId: item.singleId, floorRoomId: item.floorRoomId });
      });
    },
    etixRoom(floorRoomId) {
      this.$confirm('您确认要退出联房吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinsingle/exit_single/${floorRoomId}`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: this.$t('Common.OperationSuccessful'),
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList();
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    },
    //换房
    changeRoom(item) {
      this.changeRoomVisible = true;
      this.$nextTick(() => {
        this.$refs.changeRoom.init(item);
      });
    },

    selectSeller(id, value) {
      this.getDataList()
    },
    //加载平台商家数据
    remoteMethod(query) {
      if(this.isAuth('hotel:hotelseller:list')){
        this.loading = true;
        this.$http({
          url: this.$http.adornUrl("/hotel/hotelseller/platformSeller"),
          method: "get",
          params: this.$http.adornParams({
            sellerName: query
          })
        }).then(({ data }) => {
          this.loading = false;
          if (data && data.code === 0) {
            this.platformSeller = data.page.list;
          } else {
            this.$message.error(data.msg);
          }
        });
      }
    },
    // 加入联房
    joinRoomBtn(singleId) {
      this.joinRoomVisible = true;
      this.$nextTick(() => {
        this.$refs.joinRoom.init(singleId);
      });
    },
    init() {},
    toAccounting(item, type) {
      //将数据存储到本地
      var p = {
        singleId: item.singleId,
        type: type
      };
      this.$cookie.set('accounting', JSON.stringify(p));
      this.$router.push({
        name: 'accounting'
      });
    },
    handleClick(tab, event) {
      console.log(tab, event);
      this.getDataList();
    },
    getDataList() {
      var ids = ""
      if(this.sellerIds){
        this.sellerIds.forEach((item,index) =>{
          ids+=item+","
        })
        ids = ids.substring(0,ids.length-1)
      }
      var params = {
        page: this.pageIndex,
        limit: this.pageSize,
        ids:ids,
        tguesid:this.tguesid,
        ...this.dataForm,
      }
      this.$http({
        url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinpeople/listpeop`),
        method: 'get',
        params: this.$http.adornParams(params)
      }).then(({ data }) => {
        if (data && data.code === 0) {

          this.unitedHouseList = data.json.list;
           this.totalPage = data.json.size;


        } else {
          this.$message.error(data.msg);
        }
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    }
  }
};
</script>

<style>
.dl_drop {
  color: rgba(0, 0, 0, 0.65);
  z-index: 999;
  border-radius: 4px;
  overflow: hidden;
}
.dl_drop dd {
  padding: 0 15px;
  font-size: 13px;
  height: 35px;
  line-height: 35px;
  cursor: pointer;
  white-space: nowrap;
  margin: 0px;
}
</style>
